/**
 * 基础函数工具包
 * @param window
 * @param $
 * @param undefined
 */
(function (window, $, undefined) {

	//jQuery扩展
	$.extend($.util, {
		serializeObject: function(formId, flag) {
			var o = {};
			$.each($(formId).serializeArray(), function(index) {
				if(undefined == flag || flag == false) {
					if (this['value'] != undefined && this['value'].length > 0) {
						if (o[this['name']]) {
							o[this['name']] = o[this['name']] + "," + this['value'];
						} else {
							o[this['name']] = this['value'];
						}
					}
				} else {
					if (o[this['name']]) {
						o[this['name']] = o[this['name']] + "," + this['value'];
					} else {
						o[this['name']] = this['value'];
					}
				}
			});
			return o;
		},
		request: function(url) {
			var uri = window.location.search;
			var re = new RegExp("" + url + "=([^&?]*)", "ig");
			return ((uri.match(re)) ? (uri.match(re)[0].substr(url.length + 1)) : null);
		},
		openWin: function(url) {
			var width  = screen.availWidth-10;
			var height = screen.availHeight-50;
			var leftm  = 0;
			var topm   = 0;
			var args = "toolbar=0,location=0,maximize=1,directories=0,status=0,menubar=0,scrollbars=1, resizable=1,left=" + leftm+ ",top=" + topm + ", width="+width+", height="+height;
			var w = window.open(url,"",args);
			if(!w){
				alertify.error('发现弹出窗口被阻止，请更改浏览器设置，以便正常使用本功能！');
				return ;
			}
		}
	});
	
	//解决了IE上js不支持trim的问题
	String.prototype.trim = function() {
		return this.replace(/(^\s*)|(\s*$)/g, "");
	}
    
})(window, jQuery);

alertify.set({ delay : 3000 });
alertify.warning = alertify.extend('warning');
alertify.info = alertify.extend('info');